﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BLL
{
  public  class GetList
    {
        //获取模型的对象数组
        public static List<Models.Model> ModelList()
        {
            #region 把数据集转成对象数组
            DataTable dt = DAL.Query.QueryALL("tb_model");
            List<Models.Model> list = new List<Models.Model>();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                Models.Model model = new Models.Model();

                model.ID = Convert.ToInt32(dt.Rows[i]["ID"]);
                model.Name = dt.Rows[i]["Name"].ToString();               
                model.AdminDir = dt.Rows[i]["AdminDir"].ToString();
                model.WebDir = dt.Rows[i]["WebDir"].ToString();
                model.TableName = dt.Rows[i]["TableName"].ToString();
                model.Remark = dt.Rows[i]["Remark"].ToString();
                list.Add(model);
            }
            #endregion

            return list;
        }
        // 获取所有日志的对象数组
        public static List<Models.Log> LogList()
        {
            #region 组装日志集合
            DataTable dt = DAL.Query.QueryALL("tb_log");
            List<Models.Log> list = new List<Models.Log>();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                Models.Log e = new Models.Log();
                e.ID = Convert.ToInt32(dt.Rows[i]["ID"]);
                e.UserName = dt.Rows[i]["UserName"].ToString();
                e.UserIP = dt.Rows[i]["UserIP"].ToString();
                e.Action = dt.Rows[i]["Action"].ToString();
                e.Time = Convert.ToDateTime(dt.Rows[i]["Time"]);
                list.Add(e);
            }
            #endregion

            return list;
        }
        // 得到角色名到其ID的映射
        public static System.Collections.Hashtable RoleNameToID(bool opp = false)
        {
            DataTable dt = DAL.SpecialAction.RoleNameToID();

            Hashtable hash = new Hashtable();
            for (int i = 0; i < dt.Rows.Count; ++i)
            {
                if (opp)
                {
                    hash[dt.Rows[i]["Name"].ToString()] = dt.Rows[i]["ID"].ToString();
                }
                else
                {
                    hash[dt.Rows[i]["ID"].ToString()] = dt.Rows[i]["Name"].ToString();
                }
            }

            return hash;
        }
        // 得到用户名到其ID的映射
        public static System.Collections.Hashtable UserNameToID(bool opp = false)
        {
            DataTable dt = DAL.SpecialAction.UserNameToID();

            Hashtable hash = new Hashtable();
            for (int i = 0; i < dt.Rows.Count; ++i)
            {
                if (opp)
                {
                    hash[dt.Rows[i]["Name"].ToString()] = dt.Rows[i]["ID"].ToString();
                }
                else
                {
                    hash[dt.Rows[i]["ID"].ToString()] = dt.Rows[i]["Name"].ToString();
                }
            }

            return hash;
        }
        // 得到栏目名到其ID的映射
        public static System.Collections.Hashtable ColumnNameToID(bool opp = false)
        {
            DataTable dt = DAL.SpecialAction.ColumnNameToID();

            Hashtable hash = new Hashtable();
            for (int i = 0; i < dt.Rows.Count; ++i)
            {
                if (opp)
                {
                    hash[dt.Rows[i]["Name"].ToString()] = dt.Rows[i]["ID"].ToString();
                }
                else
                {
                    hash[dt.Rows[i]["ID"].ToString()] = dt.Rows[i]["Name"].ToString();
                }
            }

            return hash;
        }
        // 获取所有用户的对象数组
        public static List<Models.User> GetUserList()
        {
            #region 组装日志集合
            DataTable dt = DAL.Query.QueryALL("tb_user");
            List<Models.User> list = new List<Models.User>();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                Models.User e = new Models.User();
                e.ID = Convert.ToInt32(dt.Rows[i]["ID"]);
                e.RoleID = Convert.ToInt32(dt.Rows[i]["RoleID"].ToString());
                e.ParentID = Convert.ToInt32(dt.Rows[i]["ParentID"]);
                e.Name = dt.Rows[i]["Name"].ToString();
                e.Password = dt.Rows[i]["Password"].ToString();             
                e.UserEnabled = Convert.ToBoolean(dt.Rows[i]["UserEnabled"]);
                list.Add(e);
            }
            #endregion

            return list;
        }
        // 获取所有小黄侠的对象数组
        public static List<Models.Team> GeTeamList()
        {
            #region 组装日志集合
            DataTable dt = DAL.Query.QueryALL("tb_team");
            List<Models.Team> list = new List<Models.Team>();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                Models.Team e = new Models.Team();
                e.id = Convert.ToInt32(dt.Rows[i]["id"]);
                e.xuehao = dt.Rows[i]["xuehao"].ToString();
                e.name = dt.Rows[i]["name"].ToString();
                e.password = dt.Rows[i]["password"].ToString();
                e.author = dt.Rows[i]["author"].ToString();
                e.remark = dt.Rows[i]["remark"].ToString();
               
                list.Add(e);
            }
            #endregion

            return list;
        }
        // 获取所有小黄che的对象数组
        public static List<Models.ofo> GetofoList()
        {
            #region 组装日志集合
            DataTable dt = DAL.Query.QueryALL("tb_ofo");
            List<Models.ofo> list = new List<Models.ofo>();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                Models.ofo e = new Models.ofo();
                e.id = Convert.ToInt32(dt.Rows[i]["id"]);
                e.chepai = dt.Rows[i]["chepai"].ToString();           
                e.password = dt.Rows[i]["password"].ToString();
                e.author = dt.Rows[i]["author"].ToString();
                e.remark = dt.Rows[i]["remark"].ToString();

                list.Add(e);
            }
            #endregion

            return list;
        }
        //获取角色的对象数组
        public static List<Models.Role> RoleList()
        {
            #region 把数据集转成对象数组
            DataTable dt = DAL.Query.QueryALL("tb_role");
            List<Models.Role> list = new List<Models.Role>();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                Models.Role role = new Models.Role();

                role.ID = Convert.ToInt32(dt.Rows[i]["ID"]);
                role.Name = dt.Rows[i]["Name"].ToString();
                role.RoleInfoModelID = Convert.ToInt32(dt.Rows[i]["RoleInfoModelID"]);
                role.IsAdmin = Convert.ToBoolean(dt.Rows[i]["IsAdmin"]);
                role.ModelAdmin = Convert.ToBoolean(dt.Rows[i]["ModelAdmin"]);
                role.ColumnAdmin = Convert.ToBoolean(dt.Rows[i]["ColumnAdmin"]);
                role.ContentAdmin = dt.Rows[i]["ContentAdmin"].ToString();
                role.UserAdmin = Convert.ToBoolean(dt.Rows[i]["UserAdmin"]);
                role.RoleAdmin = Convert.ToBoolean(dt.Rows[i]["RoleAdmin"]);
                role.FileAdmin = Convert.ToBoolean(dt.Rows[i]["FileAdmin"]);
                role.LogAdmin = Convert.ToBoolean(dt.Rows[i]["LogAdmin"]);
                role.SystemAdmin = Convert.ToBoolean(dt.Rows[i]["SystemAdmin"]);
                role.RoleEnabled = Convert.ToBoolean(dt.Rows[i]["RoleEnabled"]);

                list.Add(role);
            }
            #endregion

            return list;
        }
      /// <summary>
      /// 获得所有栏目
      /// </summary>
      /// <returns></returns>
        public static List<Models.Column> ColumnList()
        {
            #region 把数据集转换成对象数组
            DataTable dt = DAL.Query.QueryOrder("tb_column","OrderID","asc");
            List<Models.Column> list = new List<Models.Column>();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                Models.Column e = new Models.Column();
                e.ID = Convert.ToInt32(dt.Rows[i]["ID"]);
                e.ParentID = Convert.ToInt32(dt.Rows[i]["ParentID"]);
                e.ModelID = Convert.ToInt32(dt.Rows[i]["ModelID"]);
                e.ColumnLogo = dt.Rows[i]["ColumnLogo"].ToString();
                e.Remark = dt.Rows[i]["Remark"].ToString();
                e.Name = dt.Rows[i]["Name"].ToString();
                list.Add(e);
            }
            #endregion
            return list;
        }
      /// <summary>
      /// 获取文章列表
      /// </summary>
      /// <param name="cid"></param>
      /// <param name="order_field"></param>
      /// <param name="order_value"></param>
      /// <returns></returns>
        public static List<Models.ModelArticle> GetArticleList(string cid, string order_field, string order_value)
        {
           int cluID = Convert.ToInt32(cid);
            DataTable dt = DAL.Query.QuerySomeByCid("tb_content_article", cluID, order_field, order_value);
            List<Models.ModelArticle> list = new List<Models.ModelArticle>();
            for (int i = 0; i < dt.Rows.Count; ++i)
            {
                Models.ModelArticle e = new Models.ModelArticle();
                e.ID = Convert.ToInt32(dt.Rows[i]["ID"]);
                e.FirstEditor = dt.Rows[i]["FirstEditor"].ToString();
                e.LastEditor = dt.Rows[i]["LastEditor"].ToString();
                e.ColumnID = Convert.ToInt32(dt.Rows[i]["ColumnID"]);
                e.Title = dt.Rows[i]["Title"].ToString();
                e.Content = dt.Rows[i]["Content"].ToString();
                e.Source = dt.Rows[i]["Source"].ToString();
                e.Tags = dt.Rows[i]["Tags"].ToString();
                e.UpdateDate = Convert.ToDateTime(dt.Rows[i]["UpdateDate"]);
                e.Click = Convert.ToInt32(dt.Rows[i]["Click"]);
                e.Status = Convert.ToBoolean(dt.Rows[i]["Status"]);
                list.Add(e);
            }
            return list;
        }
        public static List<Models.ModelArticle> GetArticleList(string count, string cid, string order_field, string order_value)
        {
            int cluID = Convert.ToInt32(cid);
            DataTable dt = DAL.Query.QueryAnyByCid(count, "tb_content_article", cluID, order_field, order_value);
            List<Models.ModelArticle> list = new List<Models.ModelArticle>();
            for (int i = 0; i < dt.Rows.Count; ++i)
            {
                Models.ModelArticle e = new Models.ModelArticle();
                e.ID = Convert.ToInt32(dt.Rows[i]["ID"]);
                e.FirstEditor = dt.Rows[i]["FirstEditor"].ToString();
                e.LastEditor = dt.Rows[i]["LastEditor"].ToString();
                e.ColumnID = Convert.ToInt32(dt.Rows[i]["ColumnID"]);
                e.Title = dt.Rows[i]["Title"].ToString();
                e.Content = dt.Rows[i]["Content"].ToString();
                e.Source = dt.Rows[i]["Source"].ToString();
                e.Tags = dt.Rows[i]["Tags"].ToString();
                e.UpdateDate = Convert.ToDateTime(dt.Rows[i]["UpdateDate"]);
                e.Click = Convert.ToInt32(dt.Rows[i]["Click"]);
                e.Status = Convert.ToBoolean(dt.Rows[i]["Status"]);
                list.Add(e);
            }
            return list;
        }
        // 获取滑动浏览图片模型的内容列表      
        public static List<Models.ModelSlider> GetSliderList(string cid, string order_field, string order_value)
        {
           int ClumnID = Convert.ToInt32(cid);
           DataTable dt = DAL.Query.QuerySomeByCid("tb_content_slider", ClumnID, order_field, order_value);
            List<Models.ModelSlider> list = new List<Models.ModelSlider>();
            for (int i = 0; i < dt.Rows.Count; ++i)
            {
                Models.ModelSlider e = new Models.ModelSlider();
                e.ID = Convert.ToInt32(dt.Rows[i]["ID"]);
                e.FirstEditor = dt.Rows[i]["FirstEditor"].ToString();
                e.LastEditor = dt.Rows[i]["LastEditor"].ToString();
                e.ColumnID = Convert.ToInt32(dt.Rows[i]["ColumnID"]);
                e.Title = dt.Rows[i]["Title"].ToString();
                e.PictureAddress = dt.Rows[i]["PictureAddress"].ToString();
                e.ArticleAddress = dt.Rows[i]["ArticleAddress"].ToString();
                e.Remark = dt.Rows[i]["Remark"].ToString();
                e.UpdateDate = Convert.ToDateTime(dt.Rows[i]["UpdateDate"]);              
                list.Add(e);
            }
            return list;
        }
        // 获取外链模型的内容列表      
        public static List<Models.ModelLink> GetLinkList(string cid, string order_field, string order_value)
        {
            int ClumnID = Convert.ToInt32(cid);
            DataTable dt = DAL.Query.QuerySomeByCid("tb_content_link", ClumnID, order_field, order_value);
            List<Models.ModelLink> list = new List<Models.ModelLink>();
            for (int i = 0; i < dt.Rows.Count; ++i)
            {
                Models.ModelLink e = new Models.ModelLink();
                e.ID = Convert.ToInt32(dt.Rows[i]["ID"]);
                e.FirstEditor = dt.Rows[i]["FirstEditor"].ToString();
                e.LastEditor = dt.Rows[i]["LastEditor"].ToString();
                e.ColumnID = Convert.ToInt32(dt.Rows[i]["ColumnID"]);
                e.WebUrl = dt.Rows[i]["WebUrl"].ToString();
                e.WebName = dt.Rows[i]["WebName"].ToString();
                e.WebLogo = dt.Rows[i]["WebLogo"].ToString();             
                e.UpdateDate = Convert.ToDateTime(dt.Rows[i]["UpdateDate"]);
                list.Add(e);
            }
            return list;
        }
        // 获取办公文件模型的内容列表      
        public static List<Models.ModelOfficeFile> GetOfficeFileList(string cid, string order_field, string order_value)
        {
            int ClumnID = Convert.ToInt32(cid);
            DataTable dt = DAL.Query.QuerySomeByCid("tb_content_officefile", ClumnID, order_field, order_value);
            List<Models.ModelOfficeFile> list = new List<Models.ModelOfficeFile>();
            for (int i = 0; i < dt.Rows.Count; ++i)
            {
                Models.ModelOfficeFile e = new Models.ModelOfficeFile();
                e.ID = Convert.ToInt32(dt.Rows[i]["ID"]);
                e.ColumnID = Convert.ToInt32(dt.Rows[i]["ColumnID"]);
                e.FileName = dt.Rows[i]["FileName"].ToString();
                e.FileEditor = dt.Rows[i]["FileEditor"].ToString();
                e.FileType = dt.Rows[i]["FileType"].ToString();
                e.FileSize = dt.Rows[i]["FileSize"].ToString();
                e.FileUrl = dt.Rows[i]["FileUrl"].ToString();
                e.UploadTime = Convert.ToDateTime(dt.Rows[i]["UploadTime"]);
                e.UploadSource = dt.Rows[i]["UploadSource"].ToString();
                e.download =Convert.ToInt32( dt.Rows[i]["download"]);
                e.click =Convert.ToInt32(dt.Rows[i]["click"]);
                list.Add(e);
            }
            return list;
        }
    }
}
